<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
            <title>Cindy JS</title>
            <script type="text/javascript" src="../build/js/Cindy.js"></script>

            </head>

	<body style="font-family:Arial;">

        <h1>Conics</h1>


        <script id='csmove' type='text/x-cindyscript'>
	println(Co.matrix);
	println(Co.center);
	println(Co.dualMatrix);
	println(Co.size);
        </script>


        <div  id="CSCanvas" style="width:600px; height:600px; border:2px solid #000000"></div>

        <div>
          <button id="save">Write to console</button>
        </div>

        <script type="text/javascript">

            var gslp=[
                      {name:"A", type:"Free", pos:[0,4]},
                      {name:"B", type:"Free", pos:[0,3]},
                      {name:"C", type:"Free", pos:[0,-2]},
                      {name:"D", type:"Free", pos:[5,0]},
                      {name:"E", type:"Free", pos:[-6,0]},
		              {name:"Co", type:"ConicBy5", args:["A","B","C","D","E"],color:[0,0,1],alpha:1,size:1},
//		     {name:"l", type:"Join", args:["A", "D"]}
                      ];
            var cdy=CindyJS({canvasname:"CSCanvas",
                        movescript:"csmove",
                        grid:1,
                        snap:true,
                        geometry:gslp});

            var cases = [
                ["parabola1", [0,0,1], [1,1,1], [2,4,1], [-2,4,1], [-1,1,1]],
                ["parabola2", [0, 0, 1], [0, 2, 1], [6, 2, 1], [2, 6, 1], [2, 0, 1]],
                ["parabola2b", [-.02,+.02,1], [-.02,2+.02,1], [6-.02,2+.02,1], [2-.02,6+.02,1], [2-.02,+.02,1]],
                ["hyperbola1", [2,2,1], [1,4,1], [4,1,1], [-4,-1,1], [-1,-4,1]],
                ["hyperbola2", [-0.3838383838383838,1,-0.2525252525252525], [0.25,1,0.25], [1,0.02500000000000002,-0.12499999999999997], [1,0.6298342541436464,0.138121546961326], [1,-0.8571428571428571,0.14285714285714285]],
                ["degen1", [0,4,1], [0,3,1], [0,-2,1], [5,0,1], [-6,0,1]],
                ["degen2", [0,1,0.25], [0,1,0.3333333333333333], [0,1,-0.5], [1,0.23931623931623938,0.21367521367521372], [1,0,-0.16666666666666666]],
                ["degen3", [0,1,0.25], [0.9999999999999999,-0.7826086956521738,-0.3623188405797101], [0,1,-0.5], [1,0,0.2], [1,0,-0.16666666666666666]],
["degen4", [-0.25, 1, 0.125], [0.4953271028037384, 1, 0.23364485981308416], [1, 0.33333333333333326, 0.16666666666666663], [1, 1, 0.5], [0.5, 1, 0.5]],
                ["degen5", [-0.25, 1, 0.125], [0.5643564356435643, 1, 0.24752475247524752], [1, 0.3333333333333333, 0.16666666666666666], [1, 1, 0.5], [0.5, 1, 0.5]],
                ["degen6", [-0.4962406015037595, 1, 0.09398496240601504], [0.4, 1, 0.2], [1, 0.3333333333333333, 0.16666666666666666], [1, 0.6666666666666666, 0.3333333333333333], [1, 1, 0.5]],
                ["degen7", [-0.09883720930232559, 1, 0.1453488372093023], [0.4, 1, 0.2], [1, 0.3333333333333333, 0.16666666666666666], [1, 0.6666666666666666, 0.3333333333333333], [1, 1, 0.5]],
                ["degen8", [-0.5111111111111112, 1, 0.0925925925925926], [0.4, 1, 0.2], [1, 0.3333333333333333, 0.16666666666666666], [1, 0.6666666666666666, 0.3333333333333333], [1, 1, 0.5]],
                ["almost degen", [0,1,0.25], [0.9999999999999999,0.16666666666666666,0.09689922480620154], [0,1,-0.5], [1,0.23931623931623938,0.21367521367521372], [1,0,-0.16666666666666666]],
                ["almost2", [0,1,0.25], [1,0.16666666666666674,0.09689922480620156], [0.6105263157894737,1,-0.26315789473684215], [1,0.24545454545454548,0.2272727272727273], [1,0,-0.16666666666666666]],
                ["almost3", [0,1,0.25], [1,0.7410071942446044,0.1798561151079137], [-0.8492063492063492,1,-0.1984126984126984], [1,0,0.2], [1,0,-0.16666666666666666]],
                ["circle1", [6,1,1], [10,3,1], [10,9,1], [2,9,1], [2,3,1]],
                ["circle2", [1,1,1], [-1,1,1], [1,-1,1], [1,"i",0], [-1,"i",0]],
                ["circle degen", [0,0,1], [0,2,1], [0,-2,1], [1,"i",0], [-1,"i",0]],
                ["ellipse1", [0.9999999999999999,0.44375,0.15625], [-0.6923076923076923,1,0.07692307692307693], [-0.9565217391304347,1,0.5434782608695652], [1,-0.6503496503496504,0.08741258741258742], [1,-1,1]],
                ["ellipse2", [0,1,0.25], [1,0.7410071942446044,0.1798561151079137], [-0.8492063492063492,1,-0.1984126984126984], [1,-0.18181818181818182,0.10822510822510824], [1,0,-0.16666666666666666]],
                ["ellipse3", [-0.1554770318021202,0.9999999999999999,0.08833922261484098], [1,-0.8912133891213389,-0.10460251046025104], [1,-0.06837606837606838,-0.2136752136752137], [1,0.14960629921259838,0.1968503937007874], [0.3720930232558139,0.9999999999999999,-0.29069767441860467]],
                ["ellipse4", [-0.15547703180212022,1,0.088339222614841], [1,-0.891213389121339,-0.10460251046025101], [1,-0.06837606837606836,-0.2136752136752137], [1,0.14960629921259838,0.1968503937007874], [-0.21698113207547184,1,-0.23584905660377362]],
                ["ellipse5", [-0.15547703180212022,1,0.088339222614841], [-0.695035460992908,1,0.08865248226950351], [0.8888888888888888,1,0.1111111111111111], [0.9,1,0.1], [0.08653846153846155,1,0.12019230769230768]],
                ["corners", [1.0000000000000002,0.7789115646258504,0.08503401360544219], [-0.6923076923076923,1,0.07692307692307693], [1,0.8443396226415094,-0.11792452830188678], [1,-0.6245847176079735,0.08305647840531563], [0.6363636363636365,1,-0.10822510822510824]],
                ["clipped wing", [0.3350000000000004,0.62,0.125], [0.625,0.625,0.125], [0.625,0.375,0.125], [0.5,0.5,0.125], [0.5,0.5,0.25]],
                ["clipped wing 4", [-0.25,0.75,0.125], [0.875,-0.375,0.125], [0.6875,0.125,0.0625], [0,0.5,0.125], [0.1875,-0.5,0.0625]],
                ["clipped wing 5", [-0.25,0.75,0.125], [0.875,-0.375,0.125], [0.75,-0.5,0.125], [0,0.5,0.125], [0.375,-0.875,0.125]],
                ["vanish1", [1,0.6666666666666666,0.16666666666666666], [-0.375,1,0.125], [1,0,-0.2], [1,0,0.16666666666666666], [0.9999999999999999,-0.14736842105263156,0.2631578947368421]],
            ];
            var save = document.getElementById("save");
            save.onclick = function() {
                var s = cdy.saveState();
                res = ['"?"'];
                for (var i = 0; i < 5; ++i)
                    res.push("[" + s.geometry[i].pos.join(",") + "]");
                console.log("[" + res.join(", ") + "],");
            };
            cases.forEach(function(c) {
                var btn = document.createElement("button");
                btn.innerHTML = c[0];
                save.parentNode.insertBefore(btn, save);
                btn.onclick = function() {
                    var cmd = "";
                    for (var i = 0; i < 5; ++i)
                        cmd += gslp[i].name + ".homog = [" +
                            c[i + 1].join(", ") + "];";
                    cdy.evokeCS(cmd);
                };
            });
        </script>


	</body>
</html>
